package com.sias.realestate.web.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.sias.realestate.web.model.Employee;
import com.sias.realestate.web.model.Price;
import com.sias.realestate.web.service.PriceService;
import com.sias.realestate.web.util.FinalVarUtil;
import com.sias.realestate.web.util.ViewModelUtil;
import com.sias.realstate.web.pagemodel.PageModel;

@Controller
@RequestMapping(value = "/price")
public class PriceController {
	
	@Resource
	private PriceService priceService;
	@RequestMapping(value = "/getAllPrice", method = RequestMethod.GET)
	public ModelAndView getAllPrice(HttpServletRequest request) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		ModelAndView mv = new ModelAndView();
		PageModel pageModel = new PageModel();
		List<Price> list = priceService.selectList();
		String th_list =  FinalVarUtil.priceTh; 
		pageModel.setTh_list(th_list);
		mv.addObject("pageModel", pageModel);
		mv.addObject("list", list);
		mv.setViewName("price/priceList");
		return mv;		
	}
	
	/**
	 * 
	 * @param model
	 * @param request
	 * @return 
	 * 方法说明：进入添加费用界面 
	 * 创建日期：2016年12月15日下午6:13:42
	 */
	@RequestMapping(value = "/addPriceJsp", method = RequestMethod.GET)
	public ModelAndView addPriceJsp(HttpServletRequest request)  {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("price/addPrice");
		return mv;		
	}
	/**
	 * 
	 * @param model
	 * @param request
	 * @return 
	 * 方法说明：添加费用
	 * 创建日期：2016年12月15日下午6:13:42
	 */
	@RequestMapping(value = "/addPrice", method = RequestMethod.POST)
	public ModelAndView addPrice(HttpServletRequest request,Price price)  {
		ModelAndView mv = new ModelAndView();
		priceService.insert(price);
		request.setAttribute("successInfo", "添加新费用成功！");
		request.setAttribute("page_code", "allprice");
		mv.setViewName("/success-info");
		return mv;		
	}
	/**
	 * 
	 * @param model
	 * @param request
	 * @return 
	 * 方法说明：进入修改费用界面 
	 * 创建日期：2016年12月15日下午6:13:42
	 */
	@RequestMapping(value = "/editPriceJsp", method = RequestMethod.GET)
	public ModelAndView editPriceJsp(HttpServletRequest request,Integer pid)  {
		ModelAndView mv = new ModelAndView();
		Price price = priceService.selectById(pid);
		mv.addObject("price", price);
		mv.setViewName("price/editPrice");
		return mv;		
	}
	/**
	 * 
	 * @param model
	 * @param request
	 * @return 
	 * 方法说明：修改费用
	 * 创建日期：2016年12月15日下午6:13:42
	 */
	@RequestMapping(value = "/editPrice", method = RequestMethod.POST)
	public ModelAndView editPrice(HttpServletRequest request,Price price)  {
		ModelAndView mv = new ModelAndView();
		priceService.update(price);
		request.setAttribute("successInfo", "修改费用信息成功！");
		request.setAttribute("page_code", "allprice");
		mv.setViewName("/success-info");
		return mv;		
	}
	
	/**
	 * 
	 * @param model
	 * @param request
	 * @return 
	 * 方法说明：删除费用 
	 * 创建日期：2016年12月15日下午6:13:42
	 */
	@RequestMapping(value = "/deletePrice", method = RequestMethod.GET)
	public ModelAndView deletePrice(HttpServletRequest request,Integer pid)  {
		ModelAndView mv = new ModelAndView();
		PageModel pageModel = new PageModel();
		if(pid!=null){
			priceService.delete(pid);
		}
		List<Price> list = priceService.selectList();
		String th_list =  FinalVarUtil.priceTh; 
		pageModel.setTh_list(th_list);
		mv.addObject("pageModel", pageModel);
		mv.addObject("list", list);
		mv.setViewName("price/priceList");
		return mv;		
	}

}
